package com.ruoyi.bearing.service.Impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.bearing.domain.MyModel;
import com.ruoyi.bearing.domain.MyModel;
import com.ruoyi.bearing.mapper.ZxycMapper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.bearing.mapper.BearingLifeForecastResultMapper;
import com.ruoyi.bearing.domain.BearingLifeForecastResult;
import com.ruoyi.bearing.service.IBearingLifeForecastResultService;

/**
 * 寿命预测结果Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-02-08
 */
@Service
public class BearingLifeForecastResultServiceImpl implements IBearingLifeForecastResultService 
{
    @Autowired
    private BearingLifeForecastResultMapper bearingLifeForecastResultMapper;

    @Autowired
    private ZxycMapper zxycMapper;

    /**
     * 查询寿命预测结果
     * 
     * @param id 寿命预测结果主键
     * @return 寿命预测结果
     */
    @Override
    public BearingLifeForecastResult selectBearingLifeForecastResultById(Long id)
    {
        return bearingLifeForecastResultMapper.selectBearingLifeForecastResultById(id);
    }

    /**
     * 查询寿命预测结果列表
     * 
     * @param bearingLifeForecastResult 寿命预测结果
     * @return 寿命预测结果
     */
    @Override
    public List<BearingLifeForecastResult> selectBearingLifeForecastResultList(BearingLifeForecastResult bearingLifeForecastResult)
    {
        return bearingLifeForecastResultMapper.selectBearingLifeForecastResultList(bearingLifeForecastResult);
    }

    /**
     * 新增寿命预测结果
     * 
     * @param bearingLifeForecastResult 寿命预测结果
     * @return 结果
     */
    @Override
    public int insertBearingLifeForecastResult(BearingLifeForecastResult bearingLifeForecastResult)
    {
        bearingLifeForecastResult.setCreateTime(DateUtils.getNowDate());
        bearingLifeForecastResult.setCreateTime(new Date());
        String workingCondition = bearingLifeForecastResult.getWorkingCondition();
        String id = bearingLifeForecastResult.getModel();
        MyModel model = zxycMapper.getModelName(id);
        Long sid = model.getsId();
        String smodelName = zxycMapper.getSmodelName(sid);
        String name = model.getName();
        bearingLifeForecastResult.setModelName(name);
        bearingLifeForecastResult.setModelType(smodelName);
        bearingLifeForecastResult.setWorkingConditionName(workingCondition);
        return bearingLifeForecastResultMapper.insertBearingLifeForecastResult(bearingLifeForecastResult);
    }

    /**
     * 修改寿命预测结果
     * 
     * @param bearingLifeForecastResult 寿命预测结果
     * @return 结果
     */
    @Override
    public int updateBearingLifeForecastResult(BearingLifeForecastResult bearingLifeForecastResult)
    {
        return bearingLifeForecastResultMapper.updateBearingLifeForecastResult(bearingLifeForecastResult);
    }

    /**
     * 批量删除寿命预测结果
     * 
     * @param ids 需要删除的寿命预测结果主键
     * @return 结果
     */
    @Override
    public int deleteBearingLifeForecastResultByIds(Long[] ids)
    {
        return bearingLifeForecastResultMapper.deleteBearingLifeForecastResultByIds(ids);
    }

    /**
     * 删除寿命预测结果信息
     * 
     * @param id 寿命预测结果主键
     * @return 结果
     */
    @Override
    public int deleteBearingLifeForecastResultById(Long id)
    {
        return bearingLifeForecastResultMapper.deleteBearingLifeForecastResultById(id);
    }
}
